package org.telegram.bot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.telegram.bot.domain.BotPublicBlock;
import org.telegram.bot.service.IBotPublicBlockService;

import java.util.List;

/**
 * 公共违禁词Controller
 *
 * @author wyx
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/bot/block")
@Slf4j
public class BotPublicBlockController extends BaseController
{
    @Resource
    private IBotPublicBlockService botPublicBlockService;

    /**
     * 查询公共违禁词列表
     */
    @PreAuthorize("@ss.hasPermi('bot:block:list')")
    @GetMapping("/list")
    public TableDataInfo list(BotPublicBlock botPublicBlock)
    {
        startPage();
        List<BotPublicBlock> list = botPublicBlockService.selectBotPublicBlockList(botPublicBlock);
        return getDataTable(list);
    }

    /**
     * 导出公共违禁词列表
     */
    @PreAuthorize("@ss.hasPermi('bot:block:export')")
    @Log(title = "公共违禁词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotPublicBlock botPublicBlock)
    {
        List<BotPublicBlock> list = botPublicBlockService.selectBotPublicBlockList(botPublicBlock);
        ExcelUtil<BotPublicBlock> util = new ExcelUtil<BotPublicBlock>(BotPublicBlock.class);
        util.exportExcel(response, list, "公共违禁词数据");
    }

    /**
     * 获取公共违禁词详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:block:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botPublicBlockService.selectBotPublicBlockById(id));
    }

    /**
     * 新增公共违禁词
     */
    @PreAuthorize("@ss.hasPermi('bot:block:add')")
    @Log(title = "公共违禁词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotPublicBlock botPublicBlock)
    {
        return toAjax(botPublicBlockService.insertBotPublicBlock(botPublicBlock));
    }

    /**
     * 修改公共违禁词
     */
    @PreAuthorize("@ss.hasPermi('bot:block:edit')")
    @Log(title = "公共违禁词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BotPublicBlock botPublicBlock)
    {
        return toAjax(botPublicBlockService.updateBotPublicBlock(botPublicBlock));
    }

    /**
     * 删除公共违禁词
     */
    @PreAuthorize("@ss.hasPermi('bot:block:remove')")
    @Log(title = "公共违禁词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botPublicBlockService.deleteBotPublicBlockByIds(ids));
    }
    
    /**
     * 导入公共违禁词
     */
    @Log(title = "公共违禁词", businessType = BusinessType.DELETE)
    @PostMapping("/{chatId}/{ids}")
    public AjaxResult importToChat(@PathVariable String chatId,@PathVariable Long[] ids)
    {
        return success(botPublicBlockService.importToChat(Long.valueOf(chatId),ids));
    }
}
